package cn.tedu.csmall.stock.webapi.quartz.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

// 当前配置类的作用是定义交换机\路由Key\队列的关系
// 这些定义生效后,才能正常使用RabbitMQ发送消息
@Configuration
public class RabbitMQConfig {
    // 业务中使用的交换机\路由Key\队列的名称都要用常量定义
    public static final String STOCK_EX="stock_ex";
    public static final String STOCK_ROUT="stock_rout";
    public static final String STOCK_QUEUE="stock_queue";

    // 交换机\队列是实际对象,需要保存到Spring容器的
    @Bean
    public DirectExchange stockDirectExchange(){
        return new DirectExchange(STOCK_EX);
    }
    @Bean
    public Queue stockQueue(){
        return new Queue(STOCK_QUEUE);
    }
    // 路由Key用于绑定交换机和队列的关系
    @Bean
    public Binding stockBinding(){
        return BindingBuilder.bind(stockQueue())
                .to(stockDirectExchange()).with(STOCK_ROUT);
    }


}
